//
//  YFLmvStartViewController.m
//  Music
//
//  Created by dllo on 16/6/14.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "YFLmvStartViewController.h"
#import <MediaPlayer/MediaPlayer.h>
#import "AppDelegate.h"
@interface YFLmvStartViewController ()<WKUIDelegate,WKNavigationDelegate>
//@property(nonatomic,strong) MPMoviePlayerController *player;
//@property(nonatomic,strong) MPMoviePlayerViewController *playerVc;
@end

@implementation YFLmvStartViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"MV播放";
    self.view.backgroundColor =[UIColor whiteColor];
    
    
    
    
    //视频播放横屏
   
    
    
//    if (![UIDevice currentDevice].generatesDeviceOrientationNotifications) {
//        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
//    }
//    NSLog(@"%ld",(long)[UIDevice currentDevice].orientation);
//    
//    [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

    
    
    self.wkView =[[WKWebView alloc]init];
    
    self.wkView.UIDelegate = self;
    self.wkView.navigationDelegate = self;
    
     self.wkView.frame = CGRectMake(0, 0, Screenheight,Screenwidth);
         [self.view addSubview:_wkView];
    
    [self.wkView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_urlString]]];

   // http://otmv.alicdn.com/new/mv_1_1/33/ed/33eb1d3329ce1354445e95867fbf7ced.mp4?k=b9191bc090a1aa8d&t=1466476468
    // http://otmv.alicdn.com/new/mv_1_1/2e/0b/2e1126045452a68b9471fdecda7c780b.mp4?k=1ad2121fb2031bbc&t=1466476686
    
    
   // http://otmv.alicdn.com/new/mv_1_1/2e/0b/2e1126045452a68b9471fdecda7c780b.mp4?k=9fd4d56c9a4492f9&t=1466476468
    // http://otmv.alicdn.com/new/mv_2_6/1b/13/1bfc4efa677df6166784151498908113.mp4?k=fccb61d5faded2c1&t=1466476686
    NSLog(@"==================================%@",self.urlString);
    
    
    UIButton *backButton =[UIButton buttonWithType:(UIButtonTypeRoundedRect)];
   // backButton.backgroundColor =[UIColor purpleColor];
    backButton.titleLabel.textAlignment = 0;
   // [backButton setTitle:@"返回" forState:(UIControlStateNormal)];
    [backButton setBackgroundImage:[UIImage imageNamed:@"return"] forState:(UIControlStateNormal)];
    backButton.frame = CGRectMake(0, 0, 30, 30);
    [backButton addTarget:self action:@selector(didClickedButton) forControlEvents:(UIControlEventTouchUpInside)];
    [self.wkView addSubview:backButton];
    
    
    
  // [self getVideoDataSource];
    
    
    
    
    
    
}

-(void)viewWillAppear:(BOOL)animated
{
    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    appDelegate.allowRotation = 1;
    
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:@"orientation"];//这句话是防止手动先把设备置为横屏,导致下面的语句失效.
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];
}

-(void)viewWillDisappear:(BOOL)animated
{
    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    appDelegate.allowRotation = 0;
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];//这句话是防止手动先把设备置为竖屏,导致下面的语句失效.
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:@"orientation"];
    

}




//返回按钮
-(void)didClickedButton{
  //   [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

    [self dismissViewControllerAnimated:YES completion:nil];
}

//- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
//    return UIInterfaceOrientationMaskAll;
//}
//- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
//    return NO;
//}
//- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
//    return UIInterfaceOrientationLandscapeRight;
//}




-(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
{
    NSLog(@"结束加载");
}

















//-(void)getVideoDataSource
//{
////    if (self.urlString) {
//        self.player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:self.urlString]];
//        self.player.view.frame = CGRectMake(0, 0, Screenwidth, Screenwidth);
//  
//        self.player.scalingMode = MPMovieScalingModeAspectFill;
//    CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(M_PI /2);
//    self.player.view.transform = landscapeTransform;
//        [self.view addSubview:self.player.view];
//        
//        [self.player play];
//        
//   // }
//    
//}







#pragma mark - 懒加载
//- (MPMoviePlayerViewController *)playerVc
//{
//    if (_playerVc == nil) {
//        NSURL *url = [NSURL URLWithString:_urlString];
//        
//        _playerVc = [[MPMoviePlayerViewController alloc] initWithContentURL:url];;
//    }
//    return _playerVc;
//}
//
//-(void)play {
//    [self presentMoviePlayerViewControllerAnimated:self.playerVc];
//}










- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
